// 预览图片
export function previewPic(url) {
	console.log(url);
	uni.previewImage({
		urls: url,
		longPressActions: {
			// itemList: ['发送给朋友', '保存图片', '收藏'],
			success: function(data) {
				console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
			},
			fail: function(err) {
				console.log(err.errMsg);
			}
		}
	});
}

// 获取当前时间 年月日
function getNum(i) {
	return i < 10 ? '0' + i : i
};
export function getDateFn(date) {
	var date = new Date() // 获取时间
	var year = date.getFullYear() // 获取年
	var month = date.getMonth() + 1 // 获取月
	var day = date.getDate() // 获取日

	return year + '-' + getNum(month) + '-' + getNum(day);
}

// 将中国标准时间转为年月日
export function newDate(time) {
	var date = new Date(time)
	var y = date.getFullYear()
	var m = date.getMonth() + 1
	m = m < 10 ? '0' + m : m
	var d = date.getDate()
	d = d < 10 ? '0' + d : d
	return y + '-' + m + '-' + d
}

// 获取当前时间的 年月日时分秒
export function timestampToTime(date = new Date(), separate = '-', separate2 = ':') {
	var Y = date.getFullYear();
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
	var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
	var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
	var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
	var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
	return `${Y}${separate}${M}${separate}${D} ${h}${separate2}${m}${separate2}${s}`
}

// 将时间戳转为年月日时分秒
function add0(m) {
	return m < 10 ? '0' + m : m
}

export function format(shijianchuo) {
	console.log(shijianchuo)
		// #ifdef APP-PLUS
		// if(plus.os.name == 'iOS') {
		// 	if(shijianchuo.indexOf("/")) {
		// 		shijianchuo = new Date(shijianchuo.replace(/-/g, '/'))
		// 	}else {
		// 		shijianchuo = new Date(shijianchuo)
		// 	}
		// }
		// #endif
	
	var time = new Date(shijianchuo);
	var y = time.getFullYear();
	var m = time.getMonth() + 1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
};

export function formatSeconds (theTime) {
  let theTime1 = 0
  let theTime2 = 0
  if (theTime > 60) {
    theTime1 = parseInt(theTime / 60)
    theTime = parseInt(theTime % 60)
    if (theTime1 > 60) {
      theTime2 = parseInt(theTime1 / 60)
      theTime1 = parseInt(theTime1 % 60)
    }
  }
  let result = '' + parseInt(theTime) + '秒'
  if (theTime1 > 0) {
    result = '' + parseInt(theTime1) + '分' + result
  }
  if (theTime2 > 0) {
    result = '' + parseInt(theTime2) + '小时' + result
  }
  return result
}
